<div class="panel panel-default" ng-controller="resetPasswordCtrl">
	<div class="panel-heading">修改密码</div>
	<div class="panel-body">
		<form name="pwdForm" id="reset-password-form" action="#" method="post" class="form-horizontal form-wx" novalidate>
			<div class="form-group" ng-class="hasError(pwdForm.opassword)">
				<label for="opassword" class="col-sm-2 control-label"><strong>*</strong>原密码</label>
				<div class="col-sm-4">
					<input id="opassword" name="opassword" type="password" class="form-control" autofocus ng-model="opassword" required>
					<p class="help-block fade-animate" ng-if="isError(pwdForm.opassword, 'required')"><i class="fa fa-exclamation-triangle"></i> &{'admin.reset.password.failure.opassword.required'}</p>
				</div>
			</div>
			<div class="form-group" ng-class="hasError(pwdForm.npassword)">
				<label for="npassword" class="col-sm-2 control-label"><strong>*</strong>重置密码</label>
				<div class="col-sm-4">
					<input id="npassword" name="npassword" type="password" class="form-control" ng-model="npassword" required ng-minlength="6" ng-maxlength="18">
					<p class="help-block fade-animate" ng-if="isError(pwdForm.npassword, 'required')"><i class="fa fa-exclamation-triangle"></i> &{'admin.reset.password.failure.npassword.required'}</p>
					<p class="help-block fade-animate" ng-if="isError(pwdForm.npassword, 'minlength')"><i class="fa fa-exclamation-triangle"></i> &{'admin.reset.password.failure.npassword.length'}</p>
					<p class="help-block fade-animate" ng-if="isError(pwdForm.npassword, 'maxlength')"><i class="fa fa-exclamation-triangle"></i> &{'admin.reset.password.failure.npassword.length'}</p>
				</div>
			</div>
			<div class="form-group" ng-class="hasError(pwdForm.cpassword)">
				<label for="cpassword" class="col-sm-2 control-label"><strong>*</strong>重复密码</label>
				<div class="col-sm-4">
					<input id="cpassword" name="cpassword" type="password" class="form-control" ng-model="cpassword" required vd-equals="{{npassword}}">
					<p class="help-block fade-animate" ng-if="isError(pwdForm.cpassword, 'required')"><i class="fa fa-exclamation-triangle"></i> &{'admin.reset.password.failure.cpassword.required'}</p>
					<p class="help-block fade-animate" ng-if="isError(pwdForm.cpassword, 'equals')"><i class="fa fa-exclamation-triangle"></i> &{'admin.reset.password.failure.cpassword.equals'}</p>
				</div>
			</div>
			<div class="form-group">
				<div class="col-sm-4 col-sm-offset-2">
					<button type="button" class="btn btn-success" ng-click="reset()" ng-disabled="btnDisabled()">
						<span ng-if="btn(['doing'])"><i class="fa fa-spinner fa-spin"></i> 处理中...</span>
						<span ng-if="btn(['wait'])">修改</span>
					</button>
				</div>
			</div>
		</form>
	</div>
</div>

<script type="text/javascript">
var resetPasswordCtrl = ['$scope', '$http', function($scope, $http) {
	// 定义处理方法
	angular.extend($scope, {
		btnDisabled: function() {
			return ($scope.pwdForm.$invalid || $scope.btn(['doing']));
		}, reset: function() {
			$http({
				method: 'post',
				url: '@{Admin.reset}',
				data: angular.element('#reset-password-form').serialize(),
				headers: {'Content-Type': 'application/x-www-form-urlencoded'}
			}).success(function(data) {
				if ($scope.validate(data)) {
					$scope.goto('@{Admin.sign_in}');
				}
				$scope.btn('wait');
			});
		}, init: function() {
			$scope.btn('wait');
		}
	});
	
	// 初始化
	$scope.init();
}];
</script>
